package demo2;

public class AnimalTest {
    public static void main(String[] args) {
        Animal[] animals = {
                new Dog("旺财", 3, "金毛"),
                new Cat("咪咪", 2, "白色")
        };

        for (Animal animal : animals) {
            animal.makeSound();

            if (animal instanceof Swimmable) {
                ((Swimmable) animal).swim();
            }

            if (animal instanceof Trainable) {
                ((Trainable) animal).train();
            }
            System.out.println();
        }
    }
}    